home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xneko / xneko.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-20  |  49.3 KB  |  1,880 lines

  1. /*--------------------------------------------------------------
  2.  *
  3.  *  xneko  -  X11 G-
  4.  *
  5.  *          Original Writer: Masayuki Koba
  6.  *          Programmed by Masayuki Koba, 1990
  7.  *
  8.  *          Root Window Option
  9.  *              added by Yuichi Katoh, Oct 12 1990
  10.  *--------------------------------------------------------------
  11.  *
  12.  *!!Introduction:
  13.  *
  14.  *!!!!K\@(#)xneko.c    1.1m%0%i%`$O Macintosh $N6/20/959%/%"%/%;%5%j!< "neko" $N
  15.  *!!F0:n$r X11 $G%^%M$?$b$N$G$9!#
  16.  *
  17.  *!!!!Macintosh "neko" $N=(0o$J6/20/956%$%s$K7I0U$rI=$7$D$D!"$3$N
  18.  *!!@(#)xneko.c    1.1m%0%i%`$r3'$5$s$KJ{$2$^$9!#
  19.  *
  20.  *--------------------------------------------------------------
  21.  *
  22.  *!!Special Thanks to
  23.  *
  24.  *  toshi-w !D!!Macintosh neko $N>R2p<T
  25.  *  shio-m  !D!!!VX11 $N neko $,M_$7$$!*!W$H%?%@$r$3$M$??M
  26.  *  disco   !D!!X11 /v/csc/usr/src/X11/xneko/s.xneko.c/%K%+%k!&%"1.1P%$%6!<
  27.  *
  28.  *  HOMY    !D!!/v/csc/usr/src/X11/xneko/s.xneko.c0;XE&<T
  29.  *  BNS !D!!J#?t@(#)xneko.c    1.1l!<%sBP1~C%ADs6!<T
  30.  *
  31.  *      "xneko"  Presented by Masayuki Koba (masa-k).
  32.  *
  33.  *--------------------------------------------------------------
  34.  *
  35.  *!!Manifest:
  36.  *
  37.  *!!!!K\@(#)xneko.c    1.1m%0%i%`$O Public Domain Software $G$9!#E>:\!&2~NI$O
  38.  *!!<+M3$K9T$C$F2<$5$$!#
  39.  *
  40.  *!!!!$J$*!"86:n<T$O!"K\@(#)xneko.c    1.1m%0%i%`$r;HMQ$9$k$3$H$K$h$C$F@8$8$?
  41.  *!!>c32$dITMx1W$K$D$$$F$$$C$5$$@UG$$r;}$A$^$;$s!#
  42.  *
  43.  *--------------------------------------------------------------
  44.  *
  45.  *!!Bugs:
  46.  *
  47.  *!!!!!J#1!KX11 $N .Xdefaults $N@_Dj$r$^$k$C$-$jL5;k$7$F$$$^$9!#
  48.  *
  49.  *!!!!!J#2!KG-$NF0:n$,;~4V$HF14|$7$F$$$k$?$a!"%^%&%9$N0\F0>pJs
  50.  *!!!!!!!!$r%]!<%j%s%0$7$F$$$^$9!#=>$C$F!"%^%&%9$,A4$/F0:n$7$F
  51.  *!!!!!!!!$$$J$$;~$OL5BL$J%^%&%9:BI8FI$_<h$j$r9T$C$F$7$^$$$^$9!#
  52.  *
  53.  *!!!!!J#3!K%&%#%s1.1&$,%"%$%3%s2=$5$l$F$b!"$7$i$s$W$j$GIA2h$7
  54.  *!!!!!!!!$D$E$1$^$9!#$3$NItJ,$O!"8=:_$N%&%#%s1.1&$N>uBV$r@(#) xneko.c 1.1@(#)'
  55.  *!!!!!!!!55/$7$F!"%"%$%3%s2=$5$l$F$$$k;~$O40A4$K%$s%HBT$A
  56.  *!!!!!!!!$K$J$k$h$&$K=q$-JQ$($J$1$l$P$J$j$^$;$s!# ($=$s$J$3$H!"
  57.  *!!!!!!!!$G$-$k$N$+$J$!!#X10 $G$O$G$-$^$7$?$,!#)
  58.  *
  59.  *!!!!!J#4!K%j%5%$%:8e$N%&%#%s1.1&$,6KC<$K>.$5$/$J$C$?;~$NF0:n
  60.  *!!!!!!!!$OJ]>Z$G$-$^$;$s!#
  61.  *
  62.  *!!!!!J#5!KK\Mh$J$i$P3NJ]$7$?%&%#%s1.1&$d Pixmap $O@(#)xneko.c    1.1m%0%i%`
  63.  *!!!!!!!!=*N;;~$K2rJ|$9$kI,MW$,$"$j$^$9$,!"K\@(#)xneko.c    1.1m%0%i%`$O$=$N
  64.  *!!!!!!!!$X$s$r%5%\$C$F$*$j!"Hs>o$K$*9T57$,0-$/$J$C$F$$$^$9!#
  65.  *!!!!!!!!IaDL$O exit() ;~$K%7%9/v/csc/usr/src/X11/xneko/s.xneko.c`$,M>J,$J%j%=!<%9$r2rJ|$7$F
  66.  *!!!!!!!!$/$l$^$9$,!"#O#S$K/v/csc/usr/src/X11/xneko/s.xneko.c0$,$"$k>l9g$O xneko $r2?EY$b5/
  67.  *!!!!!!!!F0$9$k$H!"$=$N$&$A%9%o67WNN0h$,ITB-$7$F$7$^$&$3$H$K
  68.  *!!!!!!!!$J$k$+$b$7$l$^$;$s!#
  69.  *
  70.  *!!!!!J#6!K;~4V$KF14|$7$FI,$:IA2h=hM}$r<B9T$9$k$?$a!"0BDj>uBV
  71.  *!!!!!!!!$G$b Idle 90 !A 95% $H$J$j!"%7%9/v/csc/usr/src/X11/xneko/s.xneko.c`#C#P#U$r 5 !A 10%
  72.  *!!!!!!!!Dx>CHq$7$^$9!#!Jxtachos $GD4$Y$^$7$?!#!K
  73.  *
  74.  *--------------------------------------------------------------
  75.  *
  76.  *!!System (Machine):
  77.  *
  78.  *!!!!K\@(#)xneko.c    1.1m%0%i%`$NF0:n$r3NG'$7$?%7%9/v/csc/usr/src/X11/xneko/s.xneko.c`9=@.$O0J2<$NDL$j!#
  79.  *
  80.  *  !&NWS-1750!"NWS-1720 (NEWS)!"NWP-512D
  81.  *  !!NEWS-OS 3.2a (UNIX 4.3BSD)!"X11 Release 2
  82.  *
  83.  *  !&NWS-1750!"NWS-1720 (NEWS)!"NWP-512D
  84.  *  !!NEWS-OS 3.3 (UNIX 4.3BSD)!"X11 Release 3
  85.  *
  86.  *  !&Sun 3!"X11 Release 4
  87.  *
  88.  *  !&LUNA!"X11 Release 3
  89.  *
  90.  *  !&DECstation 3100!"ULTRIX!"X11
  91.  *
  92.  *--------------------------------------------------------------*/
  93.  
  94.  
  95. #include <X11/Xlib.h>
  96. #include <X11/Xutil.h>
  97. #include <X11/keysym.h>
  98.  
  99. #include <stdio.h>
  100.  
  101. #include <signal.h>
  102. #include <math.h>
  103.  
  104. #ifdef  sco
  105. #include <stdlib.h>
  106. #endif
  107.  
  108. #include <sys/time.h>
  109.  
  110.  
  111. #ifndef lint
  112. static char
  113.     rcsid[] = "$Header: /afs/athena.mit.edu/user/j/jik/sipbsrc/src/xneko/RCS/xneko.c,v 1.2 90/09/01 23:40:01 jik Exp $";
  114. static char WriterMessage[] = "xneko: Programmed by Masayuki Koba, 1990";
  115. #endif
  116.  
  117.  
  118. /*
  119.  *  X11 G- 0C7/2/95^119W12:18:54!%$%k0lMw!'
  120.  *
  121.  *      "icon.xbm"      !D!!%"%$%3%s
  122.  *      "cursor.xbm"        !D!!%+!<%=%k
  123.  *      "cursor_m.xbm"  !D!!%+!<%=%k!J%^%9%/!K
  124.  *
  125.  *      "space.xbm"     !D!!%9%Z!<%9
  126.  *
  127.  *      "mati2.xbm"     !D!!BT$A#2
  128.  *      "jare2.xbm"     !D!!$8$c$l#2
  129.  *      "kaki1.xbm"     !D!!A_$-#1
  130.  *      "kaki2.xbm"     !D!!A_$-#2
  131.  *      "mati3.xbm"     !D!!BT$A#3!J$"$/$S!K
  132.  *      "sleep1.xbm"        !D!!?2$k#1
  133.  *      "sleep2.xbm"        !D!!?2$k#2
  134.  *
  135.  *      "awake.xbm"     !D!!L\3P$a
  136.  *
  137.  *      "up1.xbm"       !D!!>e#1
  138.  *      "up2.xbm"       !D!!>e#2
  139.  *      "down1.xbm"     !D!!2<#1
  140.  *      "down2.xbm"     !D!!2<#2
  141.  *      "left1.xbm"     !D!!:8#1
  142.  *      "left2.xbm"     !D!!:8#2
  143.  *      "right1.xbm"        !D!!1
  144.  *      "right2.xbm"        !D!!1
  145.  *      "upleft1.xbm"       !D!!:8>e#1
  146.  *      "upleft2.xbm"       !D!!:8>e#2
  147.  *      "upright1.xbm"      !D!!1&>e#1
  148.  *      "upright2.xbm"      !D!!1&>e#2
  149.  *      "dwleft1.xbm"       !D!!:82<#1
  150.  *      "dwleft2.xbm"       !D!!:82<#2
  151.  *      "dwright1.xbm"      !D!!1&2<#1
  152.  *      "dwright2.xbm"      !D!!1&2<#2
  153.  *
  154.  *      "utogi1.xbm"        !D!!>eKa$.#1
  155.  *      "utogi2.xbm"        !D!!>eKa$.#2
  156.  *      "dtogi1.xbm"        !D!!2<Ka$.#1
  157.  *      "dtogi2.xbm"        !D!!2<Ka$.#2
  158.  *      "ltogi1.xbm"        !D!!:8Ka$.#1
  159.  *      "ltogi2.xbm"        !D!!:8Ka$.#2
  160.  *      "rtogi1.xbm"        !D!!1&Ka$.#1
  161.  *      "rtogi2.xbm"        !D!!1&Ka$.#2
  162.  *
  163.  *  !!$3$l$i$N12:18:54!%$%k$O bitmap %3%^%s%I$GJT=82DG=$G$9!#
  164.  *
  165.  *      (bitmap size "* 32x32 ... Macintosh ICON resource size.)
  166.  *
  167.  */
  168.  
  169.  
  170. #include "bitmaps/icon.xbm"
  171. #include "bitmaps/cursor.xbm"
  172. #include "bitmaps/cursor_m.xbm"
  173.  
  174. #include "bitmaps/space.xbm"
  175.  
  176. #include "bitmaps/mati2.xbm"
  177. #include "bitmaps/jare2.xbm"
  178. #include "bitmaps/kaki1.xbm"
  179. #include "bitmaps/kaki2.xbm"
  180. #include "bitmaps/mati3.xbm"
  181. #include "bitmaps/sleep1.xbm"
  182. #include "bitmaps/sleep2.xbm"
  183.  
  184. #include "bitmaps/awake.xbm"
  185.  
  186. #include "bitmaps/up1.xbm"
  187. #include "bitmaps/up2.xbm"
  188. #include "bitmaps/down1.xbm"
  189. #include "bitmaps/down2.xbm"
  190. #include "bitmaps/left1.xbm"
  191. #include "bitmaps/left2.xbm"
  192. #include "bitmaps/right1.xbm"
  193. #include "bitmaps/right2.xbm"
  194. #include "bitmaps/upright1.xbm"
  195. #include "bitmaps/upright2.xbm"
  196. #include "bitmaps/upleft1.xbm"
  197. #include "bitmaps/upleft2.xbm"
  198. #include "bitmaps/dwleft1.xbm"
  199. #include "bitmaps/dwleft2.xbm"
  200. #include "bitmaps/dwright1.xbm"
  201. #include "bitmaps/dwright2.xbm"
  202.  
  203. #include "bitmaps/utogi1.xbm"
  204. #include "bitmaps/utogi2.xbm"
  205. #include "bitmaps/dtogi1.xbm"
  206. #include "bitmaps/dtogi2.xbm"
  207. #include "bitmaps/ltogi1.xbm"
  208. #include "bitmaps/ltogi2.xbm"
  209. #include "bitmaps/rtogi1.xbm"
  210. #include "bitmaps/rtogi2.xbm"
  211.  
  212.  
  213. #include "bitmaps/mati2_m.xbm"
  214. #include "bitmaps/jare2_m.xbm"
  215. #include "bitmaps/kaki1_m.xbm"
  216. #include "bitmaps/kaki2_m.xbm"
  217. #include "bitmaps/mati3_m.xbm"
  218. #include "bitmaps/sleep1_m.xbm"
  219. #include "bitmaps/sleep2_m.xbm"
  220.  
  221. #include "bitmaps/awake_m.xbm"
  222.  
  223. #include "bitmaps/up1_m.xbm"
  224. #include "bitmaps/up2_m.xbm"
  225. #include "bitmaps/down1_m.xbm"
  226. #include "bitmaps/down2_m.xbm"
  227. #include "bitmaps/left1_m.xbm"
  228. #include "bitmaps/left2_m.xbm"
  229. #include "bitmaps/right1_m.xbm"
  230. #include "bitmaps/right2_m.xbm"
  231. #include "bitmaps/upright1_m.xbm"
  232. #include "bitmaps/upright2_m.xbm"
  233. #include "bitmaps/upleft1_m.xbm"
  234. #include "bitmaps/upleft2_m.xbm"
  235. #include "bitmaps/dwleft1_m.xbm"
  236. #include "bitmaps/dwleft2_m.xbm"
  237. #include "bitmaps/dwright1_m.xbm"
  238. #include "bitmaps/dwright2_m.xbm"
  239.  
  240. #include "bitmaps/utogi1_m.xbm"
  241. #include "bitmaps/utogi2_m.xbm"
  242. #include "bitmaps/dtogi1_m.xbm"
  243. #include "bitmaps/dtogi2_m.xbm"
  244. #include "bitmaps/ltogi1_m.xbm"
  245. #include "bitmaps/ltogi2_m.xbm"
  246. #include "bitmaps/rtogi1_m.xbm"
  247. #include "bitmaps/rtogi2_m.xbm"
  248.  
  249.  
  250. /*
  251.  *  Dj?tDj5A
  252.  */
  253.  
  254. #define BITMAP_WIDTH        32  /* #1%-%c%i%/%?$NI} (13:26:10/%;%k) */
  255. #define BITMAP_HEIGHT       32  /* #1%-%c%i%/%?$N9b$5 (13:26:10/%;%k) */
  256.  
  257. #define WINDOW_WIDTH        320 /* %&%#%s1.1&$NI} (13:26:10/%;%k) */
  258. #define WINDOW_HEIGHT       256 /* %&%#%s1.1&$N9b$5 (13:26:10/%;%k) */
  259.  
  260. #define DEFAULT_BORDER      2   /* %\!<%@!<%5%$%: */
  261.  
  262. #define DEFAULT_WIN_X       1   /* %&%#%s1.1&@8@.#X:BI8 */
  263. #define DEFAULT_WIN_Y       1   /* %&%#%s1.1&@8@.#Y:BI8 */
  264.  
  265. #define AVAIL_KEYBUF        255
  266.  
  267. #define EVENT_MASK1     ( KeyPressMask | StructureNotifyMask )
  268.  
  269. #define EVENT_MASK2     ( KeyPressMask | \
  270.                   ExposureMask | \
  271.                   StructureNotifyMask )
  272.  
  273. #define MAX_TICK        9999        /* Odd Only! */
  274.  
  275. #define INTERVAL        500L     /* %$%s%?!</v/csc/usr/src/X11/xneko/s.xneko.ck%?%$%` */
  276.  
  277. #define NEKO_SPEED      16
  278.  
  279. #define IDLE_SPACE      6
  280.  
  281. #define NORMAL_STATE        1
  282. #define DEBUG_LIST      2
  283. #define DEBUG_MOVE      3
  284.  
  285. /* G-$N>uBVDj?t */
  286.  
  287. #define NEKO_STOP       0   /* N)$A;_$^$C$? */
  288. #define NEKO_JARE       1   /* 4i$r@v$C$F$$$k */
  289. #define NEKO_KAKI       2   /* F,$rA_$$$F$$$k */
  290. #define NEKO_AKUBI      3   /* $"$/$S$r$7$F$$$k */
  291. #define NEKO_SLEEP      4   /* ?2$F$7$^$C$? */
  292. #define NEKO_AWAKE      5   /* L\$,3P$a$? */
  293. #define NEKO_U_MOVE     6   /* >e$K0\F0Cf */
  294. #define NEKO_D_MOVE     7   /* 2<$K0\F0Cf */
  295. #define NEKO_L_MOVE     8   /* :8$K0\F0Cf */
  296. #define NEKO_R_MOVE     9   /* 1&$K0\F0Cf */
  297. #define NEKO_UL_MOVE        10  /* :8>e$K0\F0Cf */
  298. #define NEKO_UR_MOVE        11  /* 1&>e$K0\F0Cf */
  299. #define NEKO_DL_MOVE        12  /* :82<$K0\F0Cf */
  300. #define NEKO_DR_MOVE        13  /* 1&2<$K0\F0Cf */
  301. #define NEKO_U_TOGI     14  /* >e$NJI$r0z$CA_$$$F$$$k */
  302. #define NEKO_D_TOGI     15  /* 2<$NJI$r0z$CA_$$$F$$$k */
  303. #define NEKO_L_TOGI     16  /* :8$NJI$r0z$CA_$$$F$$$k */
  304. #define NEKO_R_TOGI     17  /* 1&$NJI$r0z$CA_$$$F$$$k */
  305.  
  306. /* G-$N%"%K%a!<%7%g%s7+$jJV$72s?t */
  307.  
  308. #define NEKO_STOP_TIME      4
  309. #define NEKO_JARE_TIME      10
  310. #define NEKO_KAKI_TIME      4
  311. #define NEKO_AKUBI_TIME     3
  312. #define NEKO_AWAKE_TIME     3
  313. #define NEKO_TOGI_TIME      10
  314.  
  315. #define PI_PER8         ((double)3.1415926535/(double)8)
  316.  
  317. #define DIRNAMELEN      255
  318.  
  319.  
  320. /*
  321.  *  %0%m!</v/csc/usr/src/X11/xneko/s.xneko.ckJQ?t
  322.  */
  323.  
  324. static char     *ProgramName;       /* %3%^%s%IL>>N */
  325.  
  326. Bool            BackFlag;
  327. Bool            FrontFlag;
  328. Pixmap          CopyPixmap;
  329. GC          CopyGC;
  330.  
  331. Display         *theDisplay;
  332. int         theScreen;
  333. unsigned int        theDepth;
  334. unsigned long       theBlackPixel;
  335. unsigned long       theWhitePixel;
  336. Window          theWindow;
  337. Cursor          theCursor;
  338.  
  339. static unsigned int WindowWidth;
  340. static unsigned int WindowHeight;
  341.  
  342. static int      WindowPointX;
  343. static int      WindowPointY;
  344.  
  345. static unsigned int BorderWidth = DEFAULT_BORDER;
  346.  
  347. long            IntervalTime = INTERVAL;
  348.  
  349. int         EventState;     /* %$s%H=hM}MQ >uBVJQ?t */
  350.  
  351. int         NekoTickCount;      /* G-F0:n%+%&%s%? */
  352. int         NekoStateCount;     /* G-F10l>uBV%+%&%s%? */
  353. int         NekoState;      /* G-$N>uBV */
  354.  
  355. int         MouseX;         /* %^%&%9#X:BI8 */
  356. int         MouseY;         /* %^%&%9#Y:BI8 */
  357.  
  358. int         PrevMouseX = 0;     /* D>A0$N%^%&%9#X:BI8 */
  359. int         PrevMouseY = 0;     /* D>A0$N%^%&%9#Y:BI8 */
  360.  
  361. int         NekoX;          /* G-#X:BI8 */
  362. int         NekoY;          /* G-#Y:BI8 */
  363.  
  364. int         NekoMoveDx;     /* G-0\F05wN%#X */
  365. int         NekoMoveDy;     /* G-0\F05wN%#Y */
  366.  
  367. int         NekoLastX;      /* G-:G=*IA2h#X:BI8 */
  368. int         NekoLastY;      /* G-:G=*IA2h#Y:BI8 */
  369. GC          NekoLastGC;     /* G-:G=*IA2h GC */
  370.  
  371. double          NekoSpeed = (double)NEKO_SPEED;
  372.  
  373. double          SinPiPer8Times3;    /* sin( #3&P!?#8 ) */
  374. double          SinPiPer8;      /* sin( &P!?#8 ) */
  375.  
  376. Pixmap          SpaceXbm;
  377.  
  378. Pixmap          Mati2Xbm;
  379. Pixmap          Jare2Xbm;
  380. Pixmap          Kaki1Xbm;
  381. Pixmap          Kaki2Xbm;
  382. Pixmap          Mati3Xbm;
  383. Pixmap          Sleep1Xbm;
  384. Pixmap          Sleep2Xbm;
  385.  
  386. Pixmap          AwakeXbm;
  387.  
  388. Pixmap          Up1Xbm;
  389. Pixmap          Up2Xbm;
  390. Pixmap          Down1Xbm;
  391. Pixmap          Down2Xbm;
  392. Pixmap          Left1Xbm;
  393. Pixmap          Left2Xbm;
  394. Pixmap          Right1Xbm;
  395. Pixmap          Right2Xbm;
  396. Pixmap          UpLeft1Xbm;
  397. Pixmap          UpLeft2Xbm;
  398. Pixmap          UpRight1Xbm;
  399. Pixmap          UpRight2Xbm;
  400. Pixmap          DownLeft1Xbm;
  401. Pixmap          DownLeft2Xbm;
  402. Pixmap          DownRight1Xbm;
  403. Pixmap          DownRight2Xbm;
  404.  
  405. Pixmap          UpTogi1Xbm;
  406. Pixmap          UpTogi2Xbm;
  407. Pixmap          DownTogi1Xbm;
  408. Pixmap          DownTogi2Xbm;
  409. Pixmap          LeftTogi1Xbm;
  410. Pixmap          LeftTogi2Xbm;
  411. Pixmap          RightTogi1Xbm;
  412. Pixmap          RightTogi2Xbm;
  413.  
  414. GC          SpaceGC;
  415.  
  416. GC          Mati2GC;
  417. GC          Jare2GC;
  418. GC          Kaki1GC;
  419. GC          Kaki2GC;
  420. GC          Mati3GC;
  421. GC          Sleep1GC;
  422. GC          Sleep2GC;
  423.  
  424. GC          AwakeGC;
  425.  
  426. GC          Up1GC;
  427. GC          Up2GC;
  428. GC          Down1GC;
  429. GC          Down2GC;
  430. GC          Left1GC;
  431. GC          Left2GC;
  432. GC          Right1GC;
  433. GC          Right2GC;
  434. GC          UpLeft1GC;
  435. GC          UpLeft2GC;
  436. GC          UpRight1GC;
  437. GC          UpRight2GC;
  438. GC          DownLeft1GC;
  439. GC          DownLeft2GC;
  440. GC          DownRight1GC;
  441. GC          DownRight2GC;
  442.  
  443. GC          UpTogi1GC;
  444. GC          UpTogi2GC;
  445. GC          DownTogi1GC;
  446. GC          DownTogi2GC;
  447. GC          LeftTogi1GC;
  448. GC          LeftTogi2GC;
  449. GC          RightTogi1GC;
  450. GC          RightTogi2GC;
  451.  
  452. typedef struct {
  453.     GC          *GCCreatePtr;
  454.     Pixmap      *BitmapCreatePtr;
  455.     char        *PixelPattern;
  456.     char        *MaskPattern;
  457.     unsigned int    PixelWidth;
  458.     unsigned int    PixelHeight;
  459. } BitmapGCData;
  460.  
  461. BitmapGCData    BitmapGCDataTable[] =
  462. {
  463.     { &SpaceGC, &SpaceXbm,
  464.       space_bits, space_bits, space_width, space_height },
  465.     { &Mati2GC, &Mati2Xbm,
  466.       mati2_bits, mati2_mask_bits, mati2_width, mati2_height },
  467.     { &Jare2GC, &Jare2Xbm,
  468.       jare2_bits, jare2_mask_bits, jare2_width, jare2_height },
  469.     { &Kaki1GC, &Kaki1Xbm,
  470.       kaki1_bits, kaki1_mask_bits, kaki1_width, kaki1_height },
  471.     { &Kaki2GC, &Kaki2Xbm,
  472.       kaki2_bits, kaki2_mask_bits, kaki2_width, kaki2_height },
  473.     { &Mati3GC, &Mati3Xbm,
  474.       mati3_bits, mati3_mask_bits, mati3_width, mati3_height },
  475.     { &Sleep1GC, &Sleep1Xbm,
  476.       sleep1_bits, sleep1_mask_bits, sleep1_width, sleep1_height },
  477.     { &Sleep2GC, &Sleep2Xbm,
  478.       sleep2_bits, sleep2_mask_bits, sleep2_width, sleep2_height },
  479.     { &AwakeGC, &AwakeXbm,
  480.       awake_bits, awake_mask_bits, awake_width, awake_height },
  481.     { &Up1GC, &Up1Xbm, up1_bits, up1_mask_bits, up1_width, up1_height },
  482.     { &Up2GC, &Up2Xbm, up2_bits, up2_mask_bits, up2_width, up2_height },
  483.     { &Down1GC, &Down1Xbm,
  484.       down1_bits, down1_mask_bits, down1_width, down1_height },
  485.     { &Down2GC, &Down2Xbm,
  486.       down2_bits, down2_mask_bits, down2_width, down2_height },
  487.     { &Left1GC, &Left1Xbm,
  488.       left1_bits, left1_mask_bits, left1_width, left1_height },
  489.     { &Left2GC, &Left2Xbm,
  490.       left2_bits, left2_mask_bits, left2_width, left2_height },
  491.     { &Right1GC, &Right1Xbm,
  492.       right1_bits, right1_mask_bits, right1_width, right1_height },
  493.     { &Right2GC, &Right2Xbm,
  494.       right2_bits, right2_mask_bits, right2_width, right2_height },
  495.     { &UpLeft1GC, &UpLeft1Xbm,
  496.       upleft1_bits, upleft1_mask_bits, upleft1_width, upleft1_height },
  497.     { &UpLeft2GC, &UpLeft2Xbm,
  498.       upleft2_bits, upleft2_mask_bits, upleft2_width, upleft2_height },
  499.     { &UpRight1GC, &UpRight1Xbm,
  500.       upright1_bits, upright1_mask_bits, upright1_width, upright1_height },
  501.     { &UpRight2GC, &UpRight2Xbm,
  502.       upright2_bits, upright2_mask_bits, upright2_width, upright2_height },
  503.     { &DownLeft1GC, &DownLeft1Xbm,
  504.       dwleft1_bits, dwleft1_mask_bits, dwleft1_width, dwleft1_height },
  505.     { &DownLeft2GC, &DownLeft2Xbm,
  506.       dwleft2_bits, dwleft2_mask_bits, dwleft2_width, dwleft2_height },
  507.     { &DownRight1GC, &DownRight1Xbm,
  508.       dwright1_bits, dwright1_mask_bits, dwright1_width, dwright1_height },
  509.     { &DownRight2GC, &DownRight2Xbm,
  510.       dwright2_bits, dwright2_mask_bits, dwright2_width, dwright2_height },
  511.     { &UpTogi1GC, &UpTogi1Xbm,
  512.       utogi1_bits, utogi1_mask_bits, utogi1_width, utogi1_height },
  513.     { &UpTogi2GC, &UpTogi2Xbm,
  514.       utogi2_bits, utogi2_mask_bits, utogi2_width, utogi2_height },
  515.     { &DownTogi1GC, &DownTogi1Xbm,
  516.       dtogi1_bits, dtogi1_mask_bits, dtogi1_width, dtogi1_height },
  517.     { &DownTogi2GC, &DownTogi2Xbm,
  518.       dtogi2_bits, dtogi2_mask_bits, dtogi2_width, dtogi2_height },
  519.     { &LeftTogi1GC, &LeftTogi1Xbm,
  520.       ltogi1_bits, ltogi1_mask_bits, ltogi1_width, ltogi1_height },
  521.     { &LeftTogi2GC, &LeftTogi2Xbm,
  522.       ltogi2_bits, ltogi2_mask_bits, ltogi2_width, ltogi2_height },
  523.     { &RightTogi1GC, &RightTogi1Xbm,
  524.       rtogi1_bits, rtogi1_mask_bits, rtogi1_width, rtogi1_height },
  525.     { &RightTogi2GC, &RightTogi2Xbm,
  526.       rtogi2_bits, rtogi2_mask_bits, rtogi2_width, rtogi2_height },
  527.     { NULL, NULL, NULL, NULL, NULL, NULL }
  528. };
  529.  
  530. typedef struct {
  531.     GC      *TickEvenGCPtr;
  532.     GC      *TickOddGCPtr;
  533. } Animation;
  534.  
  535. Animation   AnimationPattern[] =
  536. {
  537.     { &Mati2GC, &Mati2GC },     /* NekoState == NEKO_STOP */
  538.     { &Jare2GC, &Mati2GC },     /* NekoState == NEKO_JARE */
  539.     { &Kaki1GC, &Kaki2GC },     /* NekoState == NEKO_KAKI */
  540.     { &Mati3GC, &Mati3GC },     /* NekoState == NEKO_AKUBI */
  541.     { &Sleep1GC, &Sleep2GC },       /* NekoState == NEKO_SLEEP */
  542.     { &AwakeGC, &AwakeGC },     /* NekoState == NEKO_AWAKE */
  543.     { &Up1GC, &Up2GC }  ,       /* NekoState == NEKO_U_MOVE */
  544.     { &Down1GC, &Down2GC },     /* NekoState == NEKO_D_MOVE */
  545.     { &Left1GC, &Left2GC },     /* NekoState == NEKO_L_MOVE */
  546.     { &Right1GC, &Right2GC },       /* NekoState == NEKO_R_MOVE */
  547.     { &UpLeft1GC, &UpLeft2GC },     /* NekoState == NEKO_UL_MOVE */
  548.     { &UpRight1GC, &UpRight2GC },   /* NekoState == NEKO_UR_MOVE */
  549.     { &DownLeft1GC, &DownLeft2GC }, /* NekoState == NEKO_DL_MOVE */
  550.     { &DownRight1GC, &DownRight2GC },   /* NekoState == NEKO_DR_MOVE */
  551.     { &UpTogi1GC, &UpTogi2GC },     /* NekoState == NEKO_U_TOGI */
  552.     { &DownTogi1GC, &DownTogi2GC }, /* NekoState == NEKO_D_TOGI */
  553.     { &LeftTogi1GC, &LeftTogi2GC }, /* NekoState == NEKO_L_TOGI */
  554.     { &RightTogi1GC, &RightTogi2GC },   /* NekoState == NEKO_R_TOGI */
  555. };
  556.  
  557.  
  558. /*--------------------------------------------------------------
  559.  *
  560.  *  0C7/2/95^560W%G!<%?!&GC =i4|2=
  561.  *
  562.  *--------------------------------------------------------------*/
  563.  
  564. void
  565. InitBitmapAndGCs()
  566. {
  567.     BitmapGCData    *BitmapGCDataTablePtr;
  568.     XGCValues       theGCValues;
  569.     Pixmap      theMaskBitmap;
  570.  
  571.     theGCValues.function = GXcopy;
  572.     theGCValues.foreground = BlackPixel( theDisplay, theScreen );
  573.     theGCValues.background = WhitePixel( theDisplay, theScreen );
  574.     theGCValues.fill_style = FillTiled;
  575.  
  576.     for ( BitmapGCDataTablePtr = BitmapGCDataTable;
  577.       BitmapGCDataTablePtr->GCCreatePtr != NULL;
  578.       BitmapGCDataTablePtr++ ) {
  579.  
  580.     *(BitmapGCDataTablePtr->BitmapCreatePtr)
  581.         = XCreatePixmapFromBitmapData(
  582.           theDisplay,
  583.           RootWindow( theDisplay, theScreen ),
  584.           BitmapGCDataTablePtr->PixelPattern,
  585.           BitmapGCDataTablePtr->PixelWidth,
  586.           BitmapGCDataTablePtr->PixelHeight,
  587.           BlackPixel( theDisplay, theScreen ),
  588.           WhitePixel( theDisplay, theScreen ),
  589.           DefaultDepth( theDisplay, theScreen ) );
  590.  
  591.     theGCValues.tile = *(BitmapGCDataTablePtr->BitmapCreatePtr);
  592.  
  593.     if ( FrontFlag || BackFlag ) {
  594.         theMaskBitmap
  595.         = XCreateBitmapFromData(
  596.           theDisplay,
  597.           RootWindow( theDisplay, theScreen ),
  598.           BitmapGCDataTablePtr->MaskPattern,
  599.           BitmapGCDataTablePtr->PixelWidth,
  600.           BitmapGCDataTablePtr->PixelHeight );
  601.  
  602.         theGCValues.clip_mask = theMaskBitmap;
  603.  
  604.         if ( FrontFlag )
  605.         theGCValues.subwindow_mode = IncludeInferiors;
  606.         else
  607.         theGCValues.subwindow_mode = ClipByChildren;
  608.  
  609.         *(BitmapGCDataTablePtr->GCCreatePtr)
  610.         = XCreateGC( theDisplay, theWindow,
  611.              GCFunction | GCForeground | GCBackground |
  612.              GCTile | GCFillStyle | GCClipMask | GCSubwindowMode,
  613.              &theGCValues );
  614.  
  615.     } else {
  616.  
  617.     *(BitmapGCDataTablePtr->GCCreatePtr)
  618.         = XCreateGC( theDisplay, theWindow,
  619.              GCFunction | GCForeground | GCBackground |
  620.              GCTile | GCFillStyle,
  621.              &theGCValues );
  622.  
  623.     }
  624.     }
  625.  
  626.     if ( FrontFlag || BackFlag ) {
  627.     CopyGC = XCreateGC( theDisplay, theWindow,
  628.                GCSubwindowMode, &theGCValues );
  629.     }
  630.  
  631.     XFlush( theDisplay );
  632. }
  633.  
  634.  
  635. /*--------------------------------------------------------------
  636.  *
  637.  *  %9%/%j!<%s4D6-=i4|2=
  638.  *
  639.  *--------------------------------------------------------------*/
  640.  
  641. void
  642. InitScreen( DisplayName, theGeometry, TitleName, iconicState )
  643.     char    *DisplayName;
  644.     char    *theGeometry;
  645.     char    *TitleName;
  646.     Bool    iconicState;
  647. {
  648.     int             GeometryStatus;
  649.     XSetWindowAttributes    theWindowAttributes;
  650.     XSizeHints          theSizeHints;
  651.     unsigned long       theWindowMask;
  652.     Pixmap          theIconPixmap;
  653.     Pixmap          theCursorSource;
  654.     Pixmap          theCursorMask;
  655.     XWMHints            theWMHints;
  656.     Window          theRoot;
  657.     Colormap            theColormap;
  658.     XColor          theWhiteColor, theBlackColor, theExactColor;
  659.  
  660.     if ( ( theDisplay = XOpenDisplay( DisplayName ) ) == NULL ) {
  661.     fprintf( stderr, "%s: Can't open display", ProgramName );
  662.     if ( DisplayName != NULL ) {
  663.         fprintf( stderr, " %s.\n", DisplayName );
  664.     } else {
  665.         fprintf( stderr, ".\n" );
  666.     }
  667.     exit( 1 );
  668.     }
  669.  
  670.     theScreen = DefaultScreen( theDisplay );
  671.     theDepth = DefaultDepth( theDisplay, theScreen );
  672.  
  673.     theBlackPixel = BlackPixel( theDisplay, theScreen );
  674.     theWhitePixel = WhitePixel( theDisplay, theScreen );
  675.  
  676.     if ( !( FrontFlag || BackFlag ) ) {
  677.  
  678.     GeometryStatus = XParseGeometry( theGeometry,
  679.                      &WindowPointX, &WindowPointY,
  680.                      &WindowWidth, &WindowHeight );
  681.  
  682.     if ( !( GeometryStatus & XValue ) ) {
  683.     WindowPointX = DEFAULT_WIN_X;
  684.     }
  685.     if ( !( GeometryStatus & YValue ) ) {
  686.     WindowPointY = DEFAULT_WIN_Y;
  687.     }
  688.     if ( !( GeometryStatus & WidthValue ) ) {
  689.     WindowWidth = WINDOW_WIDTH;
  690.     }
  691.     if ( !( GeometryStatus & HeightValue ) ) {
  692.     WindowHeight = WINDOW_HEIGHT;
  693.     }
  694.  
  695.     }
  696.  
  697.     theCursorSource
  698.     = XCreateBitmapFromData( theDisplay,
  699.                  RootWindow( theDisplay, theScreen ),
  700.                  cursor_bits,
  701.                  cursor_width,
  702.                  cursor_height );
  703.  
  704.     theCursorMask
  705.     = XCreateBitmapFromData( theDisplay,
  706.                  RootWindow( theDisplay, theScreen ),
  707.                  cursor_mask_bits,
  708.                  cursor_mask_width,
  709.                  cursor_mask_height );
  710.  
  711.     theColormap = DefaultColormap( theDisplay, theScreen );
  712.  
  713.     if ( !XAllocNamedColor( theDisplay, theColormap,
  714.                 "white", &theWhiteColor, &theExactColor ) ) {
  715.     fprintf( stderr,
  716.          "%s: Can't XAllocNamedColor( \"white\" ).\n", ProgramName );
  717.     exit( 1 );
  718.     }
  719.  
  720.     if ( !XAllocNamedColor( theDisplay, theColormap,
  721.                 "black", &theBlackColor, &theExactColor ) ) {
  722.     fprintf( stderr,
  723.          "%s: Can't XAllocNamedColor( \"black\" ).\n", ProgramName );
  724.     exit( 1 );
  725.     }
  726.  
  727.     theCursor = XCreatePixmapCursor( theDisplay,
  728.                      theCursorSource, theCursorMask,
  729.                      &theBlackColor, &theWhiteColor,
  730.                      cursor_x_hot, cursor_y_hot );
  731.  
  732.     if ( FrontFlag || BackFlag ) {
  733.     theWindow = DefaultRootWindow( theDisplay );
  734.     XDefineCursor( theDisplay, theWindow, theCursor );
  735.     } else {
  736.  
  737.     theWindowAttributes.border_pixel = theBlackPixel;
  738.     theWindowAttributes.background_pixel = theWhitePixel;
  739.     theWindowAttributes.cursor = theCursor;
  740.     theWindowAttributes.override_redirect = False;
  741.  
  742.     theWindowMask = CWBackPixel     |
  743.             CWBorderPixel   |
  744.             CWCursor        |
  745.             CWOverrideRedirect;
  746.  
  747.     theWindow = XCreateWindow( theDisplay,
  748.                    RootWindow( theDisplay, theScreen ),
  749.                    WindowPointX, WindowPointY,
  750.                    WindowWidth, WindowHeight,
  751.                    BorderWidth,
  752.                    theDepth,
  753.                    InputOutput,
  754.                    CopyFromParent,
  755.                    theWindowMask,
  756.                    &theWindowAttributes );
  757.  
  758.     }
  759.  
  760.     theIconPixmap = XCreateBitmapFromData( theDisplay, theWindow,
  761.                        icon_bits,
  762.                        icon_width,
  763.                        icon_height );
  764.  
  765.     theWMHints.icon_pixmap = theIconPixmap;
  766.     if ( iconicState ) {
  767.     theWMHints.initial_state = IconicState;
  768.     } else {
  769.     theWMHints.initial_state = NormalState;
  770.     }
  771.     theWMHints.flags = IconPixmapHint | StateHint;
  772.  
  773.     XSetWMHints( theDisplay, theWindow, &theWMHints );
  774.  
  775.     theSizeHints.flags = PPosition | PSize;
  776.     theSizeHints.x = WindowPointX;
  777.     theSizeHints.y = WindowPointY;
  778.     theSizeHints.width = WindowWidth;
  779.     theSizeHints.height = WindowHeight;
  780.  
  781.     XSetNormalHints( theDisplay, theWindow, &theSizeHints );
  782.  
  783.     if ( strlen( TitleName ) >= 1 ) {
  784.     XStoreName( theDisplay, theWindow, TitleName );
  785.     XSetIconName( theDisplay, theWindow, TitleName );
  786.     } else {
  787.     XStoreName( theDisplay, theWindow, ProgramName );
  788.     XSetIconName( theDisplay, theWindow, ProgramName );
  789.     }
  790.  
  791.     if ( FrontFlag )
  792.     CopyPixmap = XCreatePixmap( theDisplay, theWindow,
  793.                    BITMAP_WIDTH, BITMAP_HEIGHT, theDepth );
  794.  
  795.     XMapWindow( theDisplay, theWindow );
  796.  
  797.     XFlush( theDisplay );
  798.  
  799.     XGetGeometry( theDisplay, theWindow,
  800.           &theRoot,
  801.           &WindowPointX, &WindowPointY,
  802.           &WindowWidth, &WindowHeight,
  803.           &BorderWidth, &theDepth );
  804.  
  805.     InitBitmapAndGCs();
  806.  
  807.     XSelectInput( theDisplay, theWindow, EVENT_MASK1 );
  808.  
  809.     XFlush( theDisplay );
  810. }
  811.  
  812.  
  813. /*--------------------------------------------------------------
  814.  *
  815.  *  %$%s%?!</v/csc/usr/src/X11/xneko/s.xneko.ck
  816.  *
  817.  *  !!$3$N4X?t$r8F$V$H!"$"$k0lDj$N;~4VJV$C$F$3$J$/$J$k!#G-
  818.  *  $NF0:n%?%$%_%s%0D4@0$KMxMQ$9$k$3$H!#
  819.  *
  820.  *--------------------------------------------------------------*/
  821.  
  822. void
  823. Interval()
  824. {
  825.     nap(IntervalTime);
  826. //    pause();
  827. }
  828.  
  829.  
  830. /*--------------------------------------------------------------
  831.  *
  832.  *  /v/csc/usr/src/X11/xneko/s.xneko.c#832/%+%&%s%H=hM}
  833.  *
  834.  *--------------------------------------------------------------*/
  835.  
  836. void
  837. TickCount()
  838. {
  839.     if ( ++NekoTickCount >= MAX_TICK ) {
  840.     NekoTickCount = 0;
  841.     }
  842.  
  843.     if ( NekoTickCount % 2 == 0 ) {
  844.     if ( NekoStateCount < MAX_TICK ) {
  845.         NekoStateCount++;
  846.     }
  847.     }
  848. }
  849.  
  850.  
  851. /*--------------------------------------------------------------
  852.  *
  853.  *  G->uBV@_Dj
  854.  *
  855.  *--------------------------------------------------------------*/
  856.  
  857. void
  858. SetNekoState( SetValue )
  859.     int     SetValue;
  860. {
  861.     NekoTickCount = 0;
  862.     NekoStateCount = 0;
  863.  
  864.     NekoState = SetValue;
  865.  
  866. #ifdef  DEBUG
  867.     switch ( NekoState ) {
  868.     case NEKO_STOP:
  869.     case NEKO_JARE:
  870.     case NEKO_KAKI:
  871.     case NEKO_AKUBI:
  872.     case NEKO_SLEEP:
  873.     case NEKO_U_TOGI:
  874.     case NEKO_D_TOGI:
  875.     case NEKO_L_TOGI:
  876.     case NEKO_R_TOGI:
  877.     NekoMoveDx = NekoMoveDy = 0;
  878.     break;
  879.     default:
  880.     break;
  881.     }
  882. #endif
  883. }
  884.  
  885.  
  886. /*--------------------------------------------------------------
  887.  *
  888.  *  G-IA2h=hM}
  889.  *
  890.  *--------------------------------------------------------------*/
  891.  
  892. void
  893. DrawNeko( x, y, DrawGC )
  894.     int     x;
  895.     int     y;
  896.     GC      DrawGC;
  897. {
  898.     if ( FrontFlag ) {
  899.     XCopyArea( theDisplay, CopyPixmap, theWindow, CopyGC, 0, 0,
  900.         BITMAP_WIDTH, BITMAP_HEIGHT, NekoLastX, NekoLastY );
  901.     XCopyArea( theDisplay, theWindow, CopyPixmap, CopyGC, x, y,
  902.         BITMAP_WIDTH, BITMAP_HEIGHT, 0,0);
  903.     } else if ( BackFlag ) {
  904.     XClearArea ( theDisplay, theWindow, NekoLastX, NekoLastY,
  905.         BITMAP_WIDTH, BITMAP_HEIGHT, True );
  906.     } else {
  907.  
  908.     if ( ( x != NekoLastX || y != NekoLastY )
  909.      && ( EventState != DEBUG_LIST ) ) {
  910.     XFillRectangle( theDisplay, theWindow, SpaceGC,
  911.             NekoLastX, NekoLastY,
  912.             BITMAP_WIDTH, BITMAP_HEIGHT );
  913.     }
  914.  
  915.     }
  916.  
  917.     XSetTSOrigin( theDisplay, DrawGC, x, y );
  918.     XSetClipOrigin( theDisplay, DrawGC, x, y );
  919.  
  920.     XFillRectangle( theDisplay, theWindow, DrawGC,
  921.             x, y, BITMAP_WIDTH, BITMAP_HEIGHT );
  922.  
  923.     XFlush( theDisplay );
  924.  
  925.     NekoLastX = x;
  926.     NekoLastY = y;
  927.  
  928.     NekoLastGC = DrawGC;
  929. }
  930.  
  931.  
  932. /*--------------------------------------------------------------
  933.  *
  934.  *  G-:FIA2h=hM}
  935.  *
  936.  *--------------------------------------------------------------*/
  937.  
  938. void
  939. RedrawNeko()
  940. {
  941.     XFillRectangle( theDisplay, theWindow, NekoLastGC,
  942.             NekoLastX, NekoLastY,
  943.             BITMAP_WIDTH, BITMAP_HEIGHT );
  944.  
  945.     XFlush( theDisplay );
  946. }
  947.  
  948.  
  949. /*--------------------------------------------------------------
  950.  *
  951.  *  G-0\F0J}K!7hDj
  952.  *
  953.  *--------------------------------------------------------------*/
  954.  
  955. void
  956. NekoDirection()
  957. {
  958.     int         NewState;
  959.     double      LargeX, LargeY;
  960.     double      Length;
  961.     double      SinTheta;
  962.  
  963.     if ( NekoMoveDx == 0 && NekoMoveDy == 0 ) {
  964.     NewState = NEKO_STOP;
  965.     } else {
  966.     LargeX = (double)NekoMoveDx;
  967.     LargeY = (double)(-NekoMoveDy);
  968.     Length = sqrt( LargeX * LargeX + LargeY * LargeY );
  969.     SinTheta = LargeY / Length;
  970.  
  971.     if ( NekoMoveDx > 0 ) {
  972.         if ( SinTheta > SinPiPer8Times3 ) {
  973.         NewState = NEKO_U_MOVE;
  974.         } else if ( ( SinTheta <= SinPiPer8Times3 )
  975.             && ( SinTheta > SinPiPer8 ) ) {
  976.         NewState = NEKO_UR_MOVE;
  977.         } else if ( ( SinTheta <= SinPiPer8 )
  978.             && ( SinTheta > -( SinPiPer8 ) ) ) {
  979.         NewState = NEKO_R_MOVE;
  980.         } else if ( ( SinTheta <= -( SinPiPer8 ) )
  981.             && ( SinTheta > -( SinPiPer8Times3 ) ) ) {
  982.         NewState = NEKO_DR_MOVE;
  983.         } else {
  984.         NewState = NEKO_D_MOVE;
  985.         }
  986.     } else {
  987.         if ( SinTheta > SinPiPer8Times3 ) {
  988.         NewState = NEKO_U_MOVE;
  989.         } else if ( ( SinTheta <= SinPiPer8Times3 )
  990.             && ( SinTheta > SinPiPer8 ) ) {
  991.         NewState = NEKO_UL_MOVE;
  992.         } else if ( ( SinTheta <= SinPiPer8 )
  993.             && ( SinTheta > -( SinPiPer8 ) ) ) {
  994.         NewState = NEKO_L_MOVE;
  995.         } else if ( ( SinTheta <= -( SinPiPer8 ) )
  996.             && ( SinTheta > -( SinPiPer8Times3 ) ) ) {
  997.         NewState = NEKO_DL_MOVE;
  998.         } else {
  999.         NewState = NEKO_D_MOVE;
  1000.         }
  1001.     }
  1002.     }
  1003.  
  1004.     if ( NekoState != NewState ) {
  1005.     SetNekoState( NewState );
  1006.     }
  1007. }
  1008.  
  1009.  
  1010. /*--------------------------------------------------------------
  1011.  *
  1012.  *  G-JI$V$D$+$jH=Dj
  1013.  *
  1014.  *--------------------------------------------------------------*/
  1015.  
  1016. Bool
  1017. IsWindowOver()
  1018. {
  1019.     Bool    ReturnValue = False;
  1020.  
  1021.     if ( NekoY <= 0 ) {
  1022.     NekoY = 0;
  1023.     ReturnValue = True;
  1024.     } else if ( NekoY >= WindowHeight - BITMAP_HEIGHT ) {
  1025.     NekoY = WindowHeight - BITMAP_HEIGHT;
  1026.     ReturnValue = True;
  1027.     }
  1028.     if ( NekoX <= 0 ) {
  1029.     NekoX = 0;
  1030.     ReturnValue = True;
  1031.     } else if ( NekoX >= WindowWidth - BITMAP_WIDTH ) {
  1032.     NekoX = WindowWidth - BITMAP_WIDTH;
  1033.     ReturnValue = True;
  1034.     }
  1035.  
  1036.     return( ReturnValue );
  1037. }
  1038.  
  1039.  
  1040. /*--------------------------------------------------------------
  1041.  *
  1042.  *  G-0\F0>u67H=Dj
  1043.  *
  1044.  *--------------------------------------------------------------*/
  1045.  
  1046. Bool
  1047. IsNekoDontMove()
  1048. {
  1049.     if ( NekoX == NekoLastX && NekoY == NekoLastY ) {
  1050.     return( True );
  1051.     } else {
  1052.     return( False );
  1053.     }
  1054. }
  1055.  
  1056.  
  1057. /*--------------------------------------------------------------
  1058.  *
  1059.  *  G-0\F03+;OH=Dj
  1060.  *
  1061.  *--------------------------------------------------------------*/
  1062.  
  1063. Bool
  1064. IsNekoMoveStart()
  1065. {
  1066. #ifndef DEBUG
  1067.     if ( ( PrevMouseX >= MouseX - IDLE_SPACE
  1068.      && PrevMouseX <= MouseX + IDLE_SPACE ) &&
  1069.      ( PrevMouseY >= MouseY - IDLE_SPACE 
  1070.      && PrevMouseY <= MouseY + IDLE_SPACE ) ) {
  1071.     return( False );
  1072.     } else {
  1073.     return( True );
  1074.     }
  1075. #else
  1076.     if ( NekoMoveDx == 0 && NekoMoveDy == 0 ) {
  1077.     return( False );
  1078.     } else {
  1079.     return( True );
  1080.     }
  1081. #endif
  1082. }
  1083.  
  1084.  
  1085. /*--------------------------------------------------------------
  1086.  *
  1087.  *  G-0\F0 dx, dy 7W;;
  1088.  *
  1089.  *--------------------------------------------------------------*/
  1090.  
  1091. void
  1092. CalcDxDy()
  1093. {
  1094.     Window      QueryRoot, QueryChild;
  1095.     int         AbsoluteX, AbsoluteY;
  1096.     int         RelativeX, RelativeY;
  1097.     unsigned int    ModKeyMask;
  1098.     double      LargeX, LargeY;
  1099.     double      DoubleLength, Length;
  1100.  
  1101.     XQueryPointer( theDisplay, theWindow,
  1102.            &QueryRoot, &QueryChild,
  1103.            &AbsoluteX, &AbsoluteY,
  1104.            &RelativeX, &RelativeY,
  1105.            &ModKeyMask );
  1106.  
  1107.     PrevMouseX = MouseX;
  1108.     PrevMouseY = MouseY;
  1109.  
  1110.     MouseX = RelativeX;
  1111.     MouseY = RelativeY;
  1112.  
  1113.     LargeX = (double)( MouseX - NekoX - BITMAP_WIDTH / 2 );
  1114.     LargeY = (double)( MouseY - NekoY - BITMAP_HEIGHT );
  1115.  
  1116.     DoubleLength = LargeX * LargeX + LargeY * LargeY;
  1117.  
  1118.     if ( DoubleLength != (double)0 ) {
  1119.     Length = sqrt( DoubleLength );
  1120.     if ( Length <= NekoSpeed ) {
  1121.         NekoMoveDx = (int)LargeX;
  1122.         NekoMoveDy = (int)LargeY;
  1123.     } else {
  1124.         NekoMoveDx = (int)( ( NekoSpeed * LargeX ) / Length );
  1125.         NekoMoveDy = (int)( ( NekoSpeed * LargeY ) / Length );
  1126.     }
  1127.     } else {
  1128.     NekoMoveDx = NekoMoveDy = 0;
  1129.     }
  1130. }
  1131.  
  1132.  
  1133. /*--------------------------------------------------------------
  1134.  *
  1135.  *  F0:n2r@OG-IA2h=hM}
  1136.  *
  1137.  *--------------------------------------------------------------*/
  1138.  
  1139. void
  1140. NekoThinkDraw()
  1141. {
  1142.     static int  OldNekoState = -1;
  1143. #ifndef DEBUG
  1144.     CalcDxDy();
  1145. #endif
  1146.  
  1147.     if ( NekoState != NEKO_SLEEP ) {
  1148.         if (OldNekoState != NekoState ||
  1149.             AnimationPattern[ NekoState ].TickEvenGCPtr !=
  1150.             AnimationPattern[ NekoState ].TickOddGCPtr )
  1151.         {
  1152.             DrawNeko( NekoX, NekoY,
  1153.                 NekoTickCount % 2 == 0 ?
  1154.                 *(AnimationPattern[ NekoState ].TickEvenGCPtr) :
  1155.                 *(AnimationPattern[ NekoState ].TickOddGCPtr) );
  1156.         }
  1157.     } else {
  1158.  
  1159.         /* added by JB to reduce onscreen flickering */
  1160.         
  1161.         if (NekoTickCount % 8 == 0 || NekoTickCount % 8 == 4)
  1162.         {
  1163.             DrawNeko( NekoX, NekoY,
  1164.                 NekoTickCount % 8 <= 3 ?
  1165.                 *(AnimationPattern[ NekoState ].TickEvenGCPtr) :
  1166.                 *(AnimationPattern[ NekoState ].TickOddGCPtr) );
  1167.  
  1168.         }
  1169.     }
  1170.  
  1171.     TickCount();
  1172.  
  1173.     switch ( NekoState ) {
  1174.     case NEKO_STOP:
  1175.     if ( IsNekoMoveStart() ) {
  1176.         SetNekoState( NEKO_AWAKE );
  1177.         break;
  1178.     }
  1179.     if ( NekoStateCount < NEKO_STOP_TIME ) {
  1180.         break;
  1181.     }
  1182.     if ( NekoMoveDx < 0 && NekoX <= 0 ) {
  1183.         SetNekoState( NEKO_L_TOGI );
  1184.     } else if ( NekoMoveDx > 0 && NekoX >= WindowWidth - BITMAP_WIDTH ) {
  1185.         SetNekoState( NEKO_R_TOGI );
  1186.     } else if ( NekoMoveDy < 0 && NekoY <= 0 ) {
  1187.         SetNekoState( NEKO_U_TOGI );
  1188.     } else if ( NekoMoveDy > 0 && NekoY >= WindowHeight - BITMAP_HEIGHT ) {
  1189.         SetNekoState( NEKO_D_TOGI );
  1190.     } else {
  1191.         SetNekoState( NEKO_JARE );
  1192.     }
  1193.     break;
  1194.     case NEKO_JARE:
  1195.     if ( IsNekoMoveStart() ) {
  1196.         SetNekoState( NEKO_AWAKE );
  1197.         break;
  1198.     }
  1199.     if ( NekoStateCount < NEKO_JARE_TIME ) {
  1200.         break;
  1201.     }
  1202.     SetNekoState( NEKO_KAKI );
  1203.     break;
  1204.     case NEKO_KAKI:
  1205.     if ( IsNekoMoveStart() ) {
  1206.         SetNekoState( NEKO_AWAKE );
  1207.         break;
  1208.     }
  1209.     if ( NekoStateCount < NEKO_KAKI_TIME ) {
  1210.         break;
  1211.     }
  1212.     SetNekoState( NEKO_AKUBI );
  1213.     break;
  1214.     case NEKO_AKUBI:
  1215.     if ( IsNekoMoveStart() ) {
  1216.         SetNekoState( NEKO_AWAKE );
  1217.         break;
  1218.     }
  1219.     if ( NekoStateCount < NEKO_AKUBI_TIME ) {
  1220.         break;
  1221.     }
  1222.     SetNekoState( NEKO_SLEEP );
  1223.     break;
  1224.     case NEKO_SLEEP:
  1225.     if ( IsNekoMoveStart() ) {
  1226.         SetNekoState( NEKO_AWAKE );
  1227.         break;
  1228.     }
  1229.     break;
  1230.     case NEKO_AWAKE:
  1231.     if ( NekoStateCount < NEKO_AWAKE_TIME ) {
  1232.         break;
  1233.     }
  1234.     NekoDirection();    /* G-$,F0$/8~$-$r5a$a$k */
  1235.     break;
  1236.     case NEKO_U_MOVE:
  1237.     case NEKO_D_MOVE:
  1238.     case NEKO_L_MOVE:
  1239.     case NEKO_R_MOVE:
  1240.     case NEKO_UL_MOVE:
  1241.     case NEKO_UR_MOVE:
  1242.     case NEKO_DL_MOVE:
  1243.     case NEKO_DR_MOVE:
  1244.     NekoX += NekoMoveDx;
  1245.     NekoY += NekoMoveDy;
  1246.     NekoDirection();
  1247.     if ( IsWindowOver() ) {
  1248.         if ( IsNekoDontMove() ) {
  1249.         SetNekoState( NEKO_STOP );
  1250.         }
  1251.     }
  1252.     break;
  1253.     case NEKO_U_TOGI:
  1254.     case NEKO_D_TOGI:
  1255.     case NEKO_L_TOGI:
  1256.     case NEKO_R_TOGI:
  1257.     if ( IsNekoMoveStart() ) {
  1258.         SetNekoState( NEKO_AWAKE );
  1259.         break;
  1260.     }
  1261.     if ( NekoStateCount < NEKO_TOGI_TIME ) {
  1262.         break;
  1263.     }
  1264.     SetNekoState( NEKO_KAKI );
  1265.     break;
  1266.     default:
  1267.     /* Internal Error */
  1268.     SetNekoState( NEKO_STOP );
  1269.     break;
  1270.     }
  1271.  
  1272.     Interval();
  1273. }
  1274.  
  1275.  
  1276. #ifdef  DEBUG
  1277.  
  1278. /*--------------------------------------------------------------
  1279.  *
  1280.  *  %-%c%i%/%?!<0lMwI=<(!J6/20/95P12800MQ!K
  1281.  *
  1282.  *--------------------------------------------------------------*/
  1283.  
  1284. void
  1285. DisplayCharacters()
  1286. {
  1287.     int     Index;
  1288.     int     x, y;
  1289.  
  1290.     for ( Index = 0, x = 0, y = 0;
  1291.       BitmapGCDataTable[ Index ].GCCreatePtr != NULL; Index++ ) {
  1292.  
  1293.     DrawNeko( x, y, *(BitmapGCDataTable[ Index ].GCCreatePtr) );
  1294.     XFlush( theDisplay );
  1295.  
  1296.     x += BITMAP_WIDTH;
  1297.  
  1298.     if ( x > WindowWidth - BITMAP_WIDTH ) {
  1299.         x = 0;
  1300.         y += BITMAP_HEIGHT;
  1301.         if ( y > WindowHeight - BITMAP_HEIGHT) {
  1302.         break;
  1303.         }
  1304.     }
  1305.     }
  1306. }
  1307.  
  1308. #endif  /* DEBUG */
  1309.  
  1310.  
  1311. /*--------------------------------------------------------------
  1312.  *
  1313.  *  %-!<%$s%H=hM}
  1314.  *
  1315.  *--------------------------------------------------------------*/
  1316.  
  1317. Bool
  1318. ProcessKeyPress( theKeyEvent )
  1319.     XKeyEvent   *theKeyEvent;
  1320. {
  1321.     int         Length;
  1322.     int         theKeyBufferMaxLen = AVAIL_KEYBUF;
  1323.     char        theKeyBuffer[ AVAIL_KEYBUF + 1 ];
  1324.     KeySym      theKeySym;
  1325.     XComposeStatus  theComposeStatus;
  1326.     Bool        ReturnState;
  1327.  
  1328.     ReturnState = True;
  1329.  
  1330.     Length = XLookupString( theKeyEvent,
  1331.                 theKeyBuffer, theKeyBufferMaxLen,
  1332.                 &theKeySym, &theComposeStatus );
  1333.  
  1334.     if ( Length > 0 ) {
  1335.     switch ( theKeyBuffer[ 0 ] ) {
  1336.     case 'q':
  1337.     case 'Q':
  1338.         if ( theKeyEvent->state & Mod1Mask ) {  /* META (Alt) %-!< */
  1339.         ReturnState = False;
  1340.         }
  1341.         break;
  1342.     default:
  1343.         break;
  1344.     }
  1345.     }
  1346.  
  1347. #ifdef  DEBUG
  1348.     if ( EventState == DEBUG_MOVE ) {
  1349.     switch ( theKeySym ) {
  1350.     case XK_KP_1:
  1351.         NekoMoveDx = -(int)( NekoSpeed / sqrt( (double)2 ) );
  1352.         NekoMoveDy = -NekoMoveDx;
  1353.         break;
  1354.     case XK_KP_2:
  1355.         NekoMoveDx = 0;
  1356.         NekoMoveDy = (int)NekoSpeed;
  1357.         break;
  1358.     case XK_KP_3:
  1359.         NekoMoveDx = (int)( NekoSpeed / sqrt( (double)2 ) );
  1360.         NekoMoveDy = NekoMoveDx;
  1361.         break;
  1362.     case XK_KP_4:
  1363.         NekoMoveDx = -(int)NekoSpeed;
  1364.         NekoMoveDy = 0;
  1365.         break;
  1366.     case XK_KP_5:
  1367.         NekoMoveDx = 0;
  1368.         NekoMoveDy = 0;
  1369.         break;
  1370.     case XK_KP_6:
  1371.         NekoMoveDx = (int)NekoSpeed;
  1372.         NekoMoveDy = 0;
  1373.         break;
  1374.     case XK_KP_7:
  1375.         NekoMoveDx = -(int)( NekoSpeed / sqrt( (double)2 ) );
  1376.         NekoMoveDy = NekoMoveDx;
  1377.         break;
  1378.     case XK_KP_8:
  1379.         NekoMoveDx = 0;
  1380.         NekoMoveDy = -(int)NekoSpeed;
  1381.         break;
  1382.     case XK_KP_9:
  1383.         NekoMoveDx = (int)( NekoSpeed / sqrt( (double)2 ) );
  1384.         NekoMoveDy = -NekoMoveDx;
  1385.         break;
  1386.     }
  1387.     }
  1388. #endif
  1389.  
  1390.     return( ReturnState );
  1391. }
  1392.  
  1393.  
  1394. /*--------------------------------------------------------------
  1395.  *
  1396.  *  G-0LCVD4@0
  1397.  *
  1398.  *--------------------------------------------------------------*/
  1399.  
  1400. void
  1401. NekoAdjust()
  1402. {
  1403.     if ( NekoX < 0 ) {
  1404.     NekoX = 0;
  1405.     } else if ( NekoX > WindowWidth - BITMAP_WIDTH ) {
  1406.     NekoX = WindowWidth - BITMAP_WIDTH;
  1407.     }
  1408.  
  1409.     if ( NekoY < 0 ) {
  1410.     NekoY = 0;
  1411.     } else if ( NekoY > WindowHeight - BITMAP_HEIGHT ) {
  1412.     NekoY = WindowHeight - BITMAP_HEIGHT;
  1413.     }
  1414. }
  1415.  
  1416.  
  1417. /*--------------------------------------------------------------
  1418.  *
  1419.  *  %$s%H=hM}
  1420.  *
  1421.  *--------------------------------------------------------------*/
  1422.  
  1423. Bool
  1424. ProcessEvent()
  1425. {
  1426.     XEvent  theEvent;
  1427.     Bool    ContinueState = True;
  1428.  
  1429.     switch ( EventState ) {
  1430.     case NORMAL_STATE:
  1431.     while ( XCheckMaskEvent( theDisplay, EVENT_MASK1, &theEvent ) ) {
  1432.         switch ( theEvent.type ) {
  1433.         case ConfigureNotify:
  1434.         WindowWidth = theEvent.xconfigure.width;
  1435.         WindowHeight = theEvent.xconfigure.height;
  1436.         WindowPointX = theEvent.xconfigure.x;
  1437.         WindowPointY = theEvent.xconfigure.y;
  1438.         BorderWidth = theEvent.xconfigure.border_width;
  1439.         NekoAdjust();
  1440.         break;
  1441.         case Expose:
  1442.         if ( theEvent.xexpose.count == 0 ) {
  1443.             RedrawNeko();
  1444.         }
  1445.         break;
  1446.         case MapNotify:
  1447.         RedrawNeko();
  1448.         break;
  1449.         case KeyPress:
  1450.         ContinueState = ProcessKeyPress( &theEvent.xkey );
  1451.         if ( !ContinueState ) {
  1452.             return( ContinueState );
  1453.         }
  1454.         break;
  1455.         default:
  1456.         /* Unknown Event */
  1457.         break;
  1458.         }
  1459.     }
  1460.     break;
  1461. #ifdef  DEBUG
  1462.     case DEBUG_LIST:
  1463.     XNextEvent( theDisplay, &theEvent );
  1464.     switch ( theEvent.type ) {
  1465.     case ConfigureNotify:
  1466.         WindowWidth = theEvent.xconfigure.width;
  1467.         WindowHeight = theEvent.xconfigure.height;
  1468.         WindowPointX = theEvent.xconfigure.x;
  1469.         WindowPointY = theEvent.xconfigure.y;
  1470.         BorderWidth = theEvent.xconfigure.border_width;
  1471.         break;
  1472.     case Expose:
  1473.         if ( theEvent.xexpose.count == 0 ) {
  1474.         DisplayCharacters();
  1475.         }
  1476.         break;
  1477.     case MapNotify:
  1478.         DisplayCharacters();
  1479.         break;
  1480.     case KeyPress:
  1481.         ContinueState = ProcessKeyPress( &theEvent );
  1482.         break;
  1483.     default:
  1484.         /* Unknown Event */
  1485.         break;
  1486.     }
  1487.     break;
  1488.     case DEBUG_MOVE:
  1489.     while ( XCheckMaskEvent( theDisplay, EVENT_MASK1, &theEvent ) ) {
  1490.         switch ( theEvent.type ) {
  1491.         case ConfigureNotify:
  1492.         WindowWidth = theEvent.xconfigure.width;
  1493.         WindowHeight = theEvent.xconfigure.height;
  1494.         WindowPointX = theEvent.xconfigure.x;
  1495.         WindowPointY = theEvent.xconfigure.y;
  1496.         BorderWidth = theEvent.xconfigure.border_width;
  1497.         NekoAdjust();
  1498.         break;
  1499.         case Expose:
  1500.         if ( theEvent.xexpose.count == 0 ) {
  1501.             RedrawNeko();
  1502.         }
  1503.         break;
  1504.         case MapNotify:
  1505.         RedrawNeko();
  1506.         break;
  1507.         case KeyPress:
  1508.         ContinueState = ProcessKeyPress( &theEvent );
  1509.         if ( !ContinueState ) {
  1510.             return( ContinueState );
  1511.         }
  1512.         break;
  1513.         default:
  1514.         /* Unknown Event */
  1515.         break;
  1516.         }
  1517.     }
  1518.     break;
  1519. #endif
  1520.     default:
  1521.     /* Internal Error */
  1522.     break;
  1523.     }
  1524.  
  1525.     return( ContinueState );
  1526. }
  1527.  
  1528.  
  1529. /*--------------------------------------------------------------
  1530.  *
  1531.  *  G-=hM}
  1532.  *
  1533.  *--------------------------------------------------------------*/
  1534.  
  1535. void
  1536. ProcessNeko()
  1537. {
  1538. //    struct itimerval    Value;
  1539.  
  1540.     /* 4D6-$N=i4|2= */
  1541.  
  1542.     EventState = NORMAL_STATE;
  1543.  
  1544.     /* G-$N=i4|2= */
  1545.  
  1546.     NekoX = ( WindowWidth - BITMAP_WIDTH / 2 ) / 2;
  1547.     NekoY = ( WindowHeight - BITMAP_HEIGHT / 2 ) / 2;
  1548.  
  1549.     if ( FrontFlag )
  1550.     XCopyArea( theDisplay, theWindow, CopyPixmap, CopyGC,
  1551.           NekoX, NekoY, BITMAP_WIDTH, BITMAP_HEIGHT, 0,0);
  1552.  
  1553.     NekoLastX = NekoX;
  1554.     NekoLastY = NekoY;
  1555.  
  1556.     SetNekoState( NEKO_STOP );
  1557.  
  1558.     /* %?%$%^!<@_Dj */
  1559. #if 0
  1560.     timerclear( &Value.it_interval );
  1561.     timerclear( &Value.it_value );
  1562.  
  1563.     Value.it_interval.tv_usec = IntervalTime;
  1564.     Value.it_value.tv_usec = IntervalTime;
  1565.  
  1566.     setitimer( ITIMER_REAL, &Value, 0 );
  1567. #endif
  1568.     /* %a%$%s=hM} */
  1569.  
  1570.     do {
  1571.     NekoThinkDraw();
  1572.     } while ( ProcessEvent() );
  1573. }
  1574.  
  1575.  
  1576. #ifdef  DEBUG
  1577.  
  1578. /*--------------------------------------------------------------
  1579.  *
  1580.  *  G-0lMw!J6/20/95P15800MQ!K
  1581.  *
  1582.  *--------------------------------------------------------------*/
  1583.  
  1584. void
  1585. NekoList()
  1586. {
  1587.     EventState = DEBUG_LIST;
  1588.  
  1589.     fprintf( stderr, "\n" );
  1590.     fprintf( stderr, "G-0lMw$rI=<($7$^$9!#(Quit !D Alt-Q)\n" );
  1591.     fprintf( stderr, "\n" );
  1592.  
  1593.     XSelectInput( theDisplay, theWindow, EVENT_MASK2 );
  1594.  
  1595.     while ( ProcessEvent() );
  1596. }
  1597.  
  1598.  
  1599. /*--------------------------------------------------------------
  1600.  *
  1601.  *  G-0\F0/v/csc/usr/src/X11/xneko/s.xneko.c9%H!J6/20/95P16010MQ!K
  1602.  *
  1603.  *--------------------------------------------------------------*/
  1604.  
  1605. void
  1606. NekoMoveTest()
  1607. {
  1608. //    struct itimerval    Value;
  1609.  
  1610.     /* 4D6-$N=i4|2= */
  1611.  
  1612.     EventState = DEBUG_MOVE;
  1613.  
  1614.     /* G-$N=i4|2= */
  1615.  
  1616.     NekoX = ( WindowWidth - BITMAP_WIDTH / 2 ) / 2;
  1617.     NekoY = ( WindowHeight - BITMAP_HEIGHT / 2 ) / 2;
  1618.  
  1619.     NekoLastX = NekoX;
  1620.     NekoLastY = NekoY;
  1621.  
  1622.     SetNekoState( NEKO_STOP );
  1623.  
  1624.     /* %?%$%^!<@_Dj */
  1625. #if 0
  1626.     timerclear( &Value.it_interval );
  1627.     timerclear( &Value.it_value );
  1628.  
  1629.     Value.it_interval.tv_usec = IntervalTime;
  1630.     Value.it_value.tv_usec = IntervalTime;
  1631.  
  1632.     setitimer( ITIMER_REAL, &Value, 0 );
  1633. #endif
  1634.     /* %a%$%s=hM} */
  1635.  
  1636.     fprintf( stderr, "\n" );
  1637.     fprintf( stderr, "G-$N0\F0/v/csc/usr/src/X11/xneko/s.xneko.c9%H$r9T$$$^$9!#(Quit !D Alt-Q)\n" );
  1638.     fprintf( stderr, "\n" );
  1639.     fprintf( stderr, "\t%-!<C%I>e$N/v/csc/usr/src/X11/xneko/s.xneko.cs%-!<$GG-$r0\F0$5$;$F2<$5$$!#\n" );
  1640.     fprintf( stderr, "\t(M-8z$J%-!<$O#1!A#9$G$9!#)\n" );
  1641.     fprintf( stderr, "\n" );
  1642.  
  1643.     do {
  1644.     NekoThinkDraw();
  1645.     } while ( ProcessEvent() );
  1646. }
  1647.  
  1648.  
  1649. /*--------------------------------------------------------------
  1650.  *
  1651.  *  %a%K%e!<=hM}!J6/20/95P16510MQ!K
  1652.  *
  1653.  *--------------------------------------------------------------*/
  1654.  
  1655. void
  1656. ProcessDebugMenu()
  1657. {
  1658.     int     UserSelectNo = 0;
  1659.     char    UserAnswer[ BUFSIZ ];
  1660.  
  1661.     fprintf( stderr, "\n" );
  1662.     fprintf( stderr, "!Zxneko 6/20/95P16620%a%K%e!<![\n" );
  1663.  
  1664.     while ( !( UserSelectNo >= 1 && UserSelectNo <= 2 ) ) {
  1665.     fprintf( stderr, "\n" );
  1666.     fprintf( stderr, "\t1)!!G-%-%c%i%/%?!<0lMwI=<(\n" );
  1667.     fprintf( stderr, "\t2)!!G-0\F0/v/csc/usr/src/X11/xneko/s.xneko.c9%H\n" );
  1668.     fprintf( stderr, "\n" );
  1669.     fprintf( stderr, "Select: " );
  1670.  
  1671.     fgets( UserAnswer, sizeof( UserAnswer ), stdin );
  1672.  
  1673.     UserSelectNo = atoi( UserAnswer );
  1674.  
  1675.     if ( !( UserSelectNo >= 1 && UserSelectNo <= 2 ) ) {
  1676.         fprintf( stderr, "\n" );
  1677.         fprintf( stderr, "@5$7$$HV9f$rA*Br$7$F2<$5$$!#\n" );
  1678.     }
  1679.     }
  1680.  
  1681.     switch ( UserSelectNo ) {
  1682.     case 1:
  1683.     /* G-%-%c%i%/%?!<0lMwI=<( */
  1684.     NekoList();
  1685.     break;
  1686.     case 2:
  1687.     /* G-0\F0/v/csc/usr/src/X11/xneko/s.xneko.c9%H */
  1688.     NekoMoveTest();
  1689.     break;
  1690.     default:
  1691.     /* Internal Error */
  1692.     break;
  1693.     }
  1694.  
  1695.     fprintf( stderr, "/v/csc/usr/src/X11/xneko/s.xneko.c9%H=*N;!#\n" );
  1696.     fprintf( stderr, "\n" );
  1697. }
  1698.  
  1699. #endif  /* DEBUG */
  1700.  
  1701.  
  1702. /*--------------------------------------------------------------
  1703.  *
  1704.  *  SIGALRM %7%0%J%k=hM}
  1705.  *
  1706.  *--------------------------------------------------------------*/
  1707.  
  1708. void
  1709. NullFunction()
  1710. {
  1711.     /* No Operation */
  1712. }
  1713.  
  1714.  
  1715. /*--------------------------------------------------------------
  1716.  *
  1717.  *  Usage
  1718.  *
  1719.  *--------------------------------------------------------------*/
  1720.  
  1721. void
  1722. Usage()
  1723. {
  1724.     fprintf( stderr,
  1725.          "Usage: %s [-display <display>] [-geometry <geometry>] \\\n",
  1726.          ProgramName );
  1727.     fprintf( stderr, "  [-title <title>] [-name <title>] [-iconic] \\\n" );
  1728.     fprintf( stderr,
  1729.         "  [-speed <speed>] [-time <time>] [-front] [-back] [-help]\n" );
  1730. }
  1731.  
  1732.  
  1733. /*--------------------------------------------------------------
  1734.  *
  1735.  *  #Xi%a!<%?I>2A
  1736.  *
  1737.  *--------------------------------------------------------------*/
  1738.  
  1739. Bool
  1740. GetArguments( argc, argv, theDisplayName, theGeometry, theTitle,
  1741.           NekoSpeed, IntervalTime )
  1742.     int     argc;
  1743.     char    *argv[];
  1744.     char    *theDisplayName;
  1745.     char    *theGeometry;
  1746.     char    *theTitle;
  1747.     double  *NekoSpeed;
  1748.     long    *IntervalTime;
  1749. {
  1750.     int     ArgCounter;
  1751.     Bool    iconicState;
  1752.  
  1753.     theDisplayName[ 0 ] = '\0';
  1754.     theGeometry[ 0 ] = '\0';
  1755.     theTitle[ 0 ] = '\0';
  1756.  
  1757.     iconicState = False;
  1758.     FrontFlag = False;
  1759.     BackFlag = False;
  1760.  
  1761.     for ( ArgCounter = 0; ArgCounter < argc; ArgCounter++ ) {
  1762.  
  1763.     if ( strncmp( argv[ ArgCounter ], "-h", 2 ) == 0 ) {
  1764.         Usage();
  1765.         exit( 0 );
  1766.     } else if ( strcmp( argv[ ArgCounter ], "-display" ) == 0 ) {
  1767.         ArgCounter++;
  1768.         if ( ArgCounter < argc ) {
  1769.         strcpy( theDisplayName, argv[ ArgCounter ] );
  1770.         } else {
  1771.         fprintf( stderr, "%s: -display option error.\n", ProgramName );
  1772.         exit( 1 );
  1773.         }
  1774.     } else if ( strncmp( argv[ ArgCounter ], "-geom", 5 ) == 0 ) {
  1775.         ArgCounter++;
  1776.         if ( ArgCounter < argc ) {
  1777.         strcpy( theGeometry, argv[ ArgCounter ] );
  1778.         } else {
  1779.         fprintf( stderr,
  1780.              "%s: -geometry option error.\n", ProgramName );
  1781.         exit( 1 );
  1782.         }
  1783.     } else if ( ( strcmp( argv[ ArgCounter ], "-title" ) == 0 )
  1784.          || ( strcmp( argv[ ArgCounter ], "-name" ) == 0 ) ) {
  1785.         ArgCounter++;
  1786.         if ( ArgCounter < argc ) {
  1787.         strcpy( theTitle, argv[ ArgCounter ] );
  1788.         } else {
  1789.         fprintf( stderr, "%s: -title option error.\n", ProgramName );
  1790.         exit( 1 );
  1791.         }
  1792.     } else if ( strcmp( argv[ ArgCounter ], "-iconic" ) == 0 ) {
  1793.         iconicState = True;
  1794.     } else if ( strcmp( argv[ ArgCounter ], "-speed" ) == 0 ) {
  1795.         ArgCounter++;
  1796.         if ( ArgCounter < argc ) {
  1797.         *NekoSpeed = atof( argv[ ArgCounter ] );
  1798.         } else {
  1799.         fprintf( stderr, "%s: -speed option error.\n", ProgramName );
  1800.         exit( 1 );
  1801.         }
  1802.     } else if ( strcmp( argv[ ArgCounter ], "-time" ) == 0 ) {
  1803.         ArgCounter++;
  1804.         if ( ArgCounter < argc ) {
  1805.         *IntervalTime = atol( argv[ ArgCounter ] );
  1806.         } else {
  1807.         fprintf( stderr, "%s: -time option error.\n", ProgramName );
  1808.         exit( 1 );
  1809.         }
  1810.     } else if ( strcmp( argv[ ArgCounter ], "-front" ) == 0 ) {
  1811.         FrontFlag = True;
  1812.         BackFlag = False;
  1813.     } else if ( strcmp( argv[ ArgCounter ], "-back" ) == 0 ) {
  1814.         BackFlag = True;
  1815.         FrontFlag = False;
  1816.     } else {
  1817.         fprintf( stderr,
  1818.              "%s: Unknown option \"%s\".\n", ProgramName,
  1819.                              argv[ ArgCounter ] );
  1820.         Usage();
  1821.         exit( 1 );
  1822.     }
  1823.     }
  1824.  
  1825.     if ( strlen( theDisplayName ) < 1 ) {
  1826.     theDisplayName = NULL;
  1827.     }
  1828.  
  1829.     if ( strlen( theGeometry ) < 1 ) {
  1830.     theGeometry = NULL;
  1831.     }
  1832.  
  1833.     return( iconicState );
  1834. }
  1835.  
  1836.  
  1837. /*--------------------------------------------------------------
  1838.  *
  1839.  *  %a%$%s4X?t
  1840.  *
  1841.  *--------------------------------------------------------------*/
  1842.  
  1843. int
  1844. main( argc, argv )
  1845.     int     argc;
  1846.     char    *argv[];
  1847. {
  1848.     Bool    iconicState;
  1849.     char    theDisplayName[ DIRNAMELEN ];
  1850.     char    theGeometry[ DIRNAMELEN ];
  1851.     char    theTitle[ DIRNAMELEN ];
  1852.  
  1853.     ProgramName = argv[ 0 ];
  1854.  
  1855.     argc--;
  1856.     argv++;
  1857.  
  1858.     iconicState = GetArguments( argc, argv,
  1859.                 theDisplayName,
  1860.                 theGeometry,
  1861.                 theTitle,
  1862.                 &NekoSpeed,
  1863.                 &IntervalTime );
  1864.  
  1865.     InitScreen( theDisplayName, theGeometry, theTitle, iconicState );
  1866.  
  1867.     signal( SIGALRM, NullFunction );
  1868.  
  1869.     SinPiPer8Times3 = sin( PI_PER8 * (double)3 );
  1870.     SinPiPer8 = sin( PI_PER8 );
  1871.  
  1872. #ifndef DEBUG
  1873.     ProcessNeko();
  1874. #else
  1875.     ProcessDebugMenu();
  1876. #endif
  1877.  
  1878.     exit( 0 );
  1879. }
  1880.